<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/3/16
 * Time: 17:25
 */

namespace Biz\model\trade;


class OrderLogistics extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_trade';

    const _DATABASE_ = 'shop_trade';

    const _TABLE_NAME = 'order_logistics_log';

    const STATUS_NO_TRACK = 0;
    const STATUS_COLLECTED = 1;
    const STATUS_PASSAGE = 2;
    const STATUS_SIGN = 3;
    const STATUS_PROBLEM_PARTS = 4;
    const STATUS_SUCCESS = 5;

    const TYPES_MAPS = [
        self::STATUS_NO_TRACK => '无轨迹', // notfound
        self::STATUS_COLLECTED => '已揽收', // transit
        self::STATUS_PASSAGE => "在途中",  //transit
        self::STATUS_SIGN => "已签收", //delivered
        self::STATUS_PROBLEM_PARTS => "问题件", // exception
        self::STATUS_SUCCESS => "确认收货",
    ];

    public static function getOrderLogistics($where, $field = '*')
    {
        $list = self::get($field, $where);
        if (empty($list)) {
            return [];
        }

        return $list;
    }

    public static function getOrdersLogistics($field, $where)
    {
        $list = self::select($field, $where);
        if (empty($list)) {
            return [];
        }

        return $list;
    }

    public static function getMultiOrderLogistics($field, $uid, $orderNos)
    {
        return self::select($field, [
            'AND'=>[
                'uid' => $uid,
                'order_no' => $orderNos,
            ],
        ]);

    }

    public static function insertLogistics($order_data)
    {
        return self::insert($order_data)->rowCount();
    }

    public static function updateLogistics($map, $data)
    {
        return self::update($data, $map)->rowCount();
    }

    public static function getLogisticsCoutn($uid, $status)
    {
        return self::count(['uid'=>$uid, 'status[!]'=>$status]);
    }

    public static function getByWhere($method, $fields,$where)
    {
        return self::$method($fields, $where);
    }
}